package com.kai.controller;

import com.alibaba.fastjson.JSONObject;
import com.kai.dto.UserWithdrawResponeDto;
import com.kai.Util.ResultMsg;
import com.kai.Util.ResultStatusCode;
import com.kai.dto.WalletBlockHeightResponeDto;
import com.kai.entity.*;
import com.kai.service.ExportService;
import com.kai.service.WalletService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.Map;

/**
 * Created by zhangkai on18/8/3
 *获取用户列表
 */
@Component
@RestController
@RequestMapping("/wallet")
public class WalletPalteListController {

    private static Logger log = LoggerFactory.getLogger(WalletPalteListController.class);

    @Autowired
    WalletService walletService;
    @Autowired
    ExportService exportService;

    /**
     * 获取平台地址扫块列表
     * @return
     */
    @PostMapping (value = "/list")
    @ResponseBody
    public Map<String, Object>  getListpage(@RequestBody WalletPlatformEntry w){
        return walletService.getWalletPlatformData(w);
    }


    /**
     * 获取提现列表
     *
     */
    @PostMapping (value = "/withdrawList")
    @ResponseBody
    public Map<String, Object>  getListpage(@RequestBody WalletPlatformOut w){
        return walletService.getWalleWithDrawData(w);
    }

    /**
     * 冷钱包地址管理
     * @param w
     * @return
     */
    @PostMapping (value = "/walletColdList")
    @ResponseBody
    public Map<String, Object>  getListpage(@RequestBody WalletCold w){
        return walletService.getWalletColdData(w);
    }


    /**
     * 热钱包地址管理
     * @param w
     * @return
     */
    @PostMapping (value = "/walletPlatformList")
    @ResponseBody
    public Map<String, Object>  getListpage(@RequestBody WalletPlatform w){
        return walletService.getWalletPlatformData(w);
    }


    /**
     * 用户地址管理
     * @param
     * @return
     */
    @PostMapping (value = "/walletHotList")
    @ResponseBody
    public Map<String, Object>  getListpage(@RequestBody JSONObject request){
        WalletHot wh=new WalletHot();
        if(request.get("userName") !=null){
            wh.setUserName(request.get("userName").toString());
        }
        if(request.get("walletAddressHash") !=null){
            wh.setWalletAddressHash(request.get("walletAddressHash").toString());
        }
        Integer num=1;
        Integer size=10;
        if(request.get("pageNum") !=null){
           num= Integer.valueOf(request.get("pageNum").toString());
        }
        if(request.get("pageSize") !=null){
            size= Integer.valueOf(request.get("pageSize").toString());
        }
        return walletService.getWalletHotData(wh,num,size);
    }




    /**
     * 导出列表
     * @param response
     */
    @GetMapping (value = "/exportWalletHotList")
    public void   ExportWalletHot(HttpServletResponse response){
        WalletHot w =new WalletHot();
        exportService.exportwalletHotBasicInfo(w,response);
    }


    /**
     *用户充值记录
     * @param w
     * @return
     */
    @PostMapping (value = "/withdrawEntryList")
    @ResponseBody
    public Map<String, Object>  getListpage(@RequestBody UserWithdrawResponeDto w){
        return walletService.getWalletHotEntry(w);
    }

    /**
     * 冷钱包地址插入
     */
    @PostMapping (value = "/insetColdAddress")
    @ResponseBody
    public ResultMsg insetColdAddress (@RequestBody WalletCold w){
        w.setCreateTime((int)(new Date().getTime()/1000));
        int i=walletService.insertCold(w);
        ResultMsg resultMsg;
        if(i>0){
            resultMsg = new ResultMsg(ResultStatusCode.OK.getCode(), ResultStatusCode.OK.getMsg(), i);
        }else{
            resultMsg = new ResultMsg(ResultStatusCode.EORROR.getCode(), ResultStatusCode.OK.getMsg(), i);
        }

        return resultMsg;
    }


    /**
     * 冷钱包地址插入
     */
    @PostMapping (value = "/insetPlateAddress")
    @ResponseBody
    public ResultMsg  insetPlateAddress(@RequestBody WalletPlatform w){
        w.setCreateTime((int)new Date().getTime()/1000);
        int i=walletService.insertPlate(w);
        ResultMsg resultMsg;
        if(i>0){
            resultMsg = new ResultMsg(ResultStatusCode.OK.getCode(), ResultStatusCode.OK.getMsg(), i);
        }else{
            resultMsg = new ResultMsg(ResultStatusCode.EORROR.getCode(), ResultStatusCode.OK.getMsg(), i);
        }

        return resultMsg;
    }

    /**
     * 区块高度
     */
    @PostMapping (value = "/getBlockHeight")
    @ResponseBody
    public ResultMsg  insetPlateAddress(){
        int id=2;
        WalletBlockHeightResponeDto i=walletService.selectBlockheight(2);
        ResultMsg resultMsg;
        if(i!=null){
            resultMsg = new ResultMsg(ResultStatusCode.OK.getCode(), ResultStatusCode.OK.getMsg(), i);
        }else{
            resultMsg = new ResultMsg(ResultStatusCode.EORROR.getCode(), ResultStatusCode.OK.getMsg(), i);
        }
        return resultMsg;
    }



}